<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/resources/template/template.xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:pe="http://primefaces.org/ui/extensions"
                xmlns:hr="http://java.sun.com/jsf/composite/autocomplete">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >  
                <p:panel>
                    <f:facet name="header">
                        <h:outputLabel value="Loan And Advances"/>
                    </f:facet>

                    <h:panelGrid columns="2" >
                        <h:outputLabel value="Component "/>
                        <p:selectOneMenu value="#{staffLoanController.current.paysheetComponent}">
                            <f:selectItem itemLabel="Select Component"/>
                            <f:selectItems value="#{staffLoanController.compnent}"
                                           var="i"  itemLabel="#{i.name}" itemValue="#{i}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="From"/>
                        <p:calendar  value="#{staffLoanController.current.fromDate}"  navigator="true" pattern="dd MM yyyy">                            
                        </p:calendar>
                        <h:outputLabel value="To"/>
                        <p:calendar   value="#{staffLoanController.current.toDate}" navigator="true" pattern="dd MM yyyy">                            
                        </p:calendar>
                        <h:outputLabel value="Staff "/>
                        <hr:completeStaff value="#{staffLoanController.current.staff}"/>
                        <h:outputLabel value="Loan No"/>
                        <p:inputText autocomplete="off"  value="#{staffLoanController.current.loanNo}"/>
                        <h:outputLabel value="Account No"/>
                        <p:inputText autocomplete="off"  value="#{staffLoanController.current.accountNo}"/>
                        <p:outputLabel value="Bank Branch"/>                                           
                        <hr:completeBank_Branch value="#{staffLoanController.current.bankBranch}"/>  
                        <h:outputLabel value="Starting Balance"/>
                        <p:inputText autocomplete="off"  value="#{staffLoanController.current.startingBalance}"/>
                        <h:outputLabel value="Full Amount"/>
                        <p:inputText autocomplete="off"  value="#{staffLoanController.current.loanFullAmount}"/>  
                        <h:outputLabel/>
                        <p:selectBooleanCheckbox value="#{staffLoanController.current.sheduleForPaid}" 
                                                 itemLabel="Shedule For Paid"/>
                        <h:outputLabel value="Monthly Installment"/>                        
                        <p:inputText autocomplete="off"  value="#{staffLoanController.current.staffPaySheetComponentValue}"/>                    
                        <h:outputLabel value="Comments"/>
                        <p:inputText autocomplete="off"  value="#{staffLoanController.current.comment}"/>
                        <h:outputLabel/>
                        <p:selectBooleanCheckbox value="#{staffLoanController.current.completed}" 
                                                 itemLabel="Completed" >
                            <f:ajax event="change" render="calComplete" execute="@this" />
                        </p:selectBooleanCheckbox>
                        <h:outputLabel value="Complete Date"/>
                        <p:calendar id="calComplete" value="#{staffLoanController.current.completedAt}"  navigator="true" pattern="dd MM yyyy"  />
                        <p:commandButton value="Save" action="#{staffLoanController.save}" ajax="false" />
                        <p:commandButton value="Clear" action="#{staffLoanController.makeNull}" ajax="false" />
                        <p:commandButton value="Remove" action="#{staffLoanController.remove}" ajax="false" />
                    </h:panelGrid>
                </p:panel>
                <p:spacer height="30" />

                <p:panel>
                    <f:facet name="header">
                        <h:outputLabel value="Loan And Advances Search"/>
                    </f:facet>
                    <h:panelGrid columns="2" >
                        <h:outputLabel value="From : " />

                        <p:calendar navigator="true" value="#{staffLoanController.fromDate}" pattern="dd MMMM yyyy hh:mm:ss a" />                       
                        <h:outputLabel value="Component "/>
                        <p:selectOneMenu value="#{staffLoanController.paysheetComponent}">
                            <f:selectItem itemLabel="Select Component"/>
                            <f:selectItems value="#{staffLoanController.compnent}"
                                           var="i"  itemLabel="#{i.name}" itemValue="#{i}"/>
                        </p:selectOneMenu>
                        <h:outputLabel value="Employee : "/>
                        <hr:completeStaff value="#{staffLoanController.reportKeyWord.staff}"/>
                        <h:outputLabel value="Department : "/>
                        <hr:department value="#{staffLoanController.reportKeyWord.department}"/>
                        <h:outputLabel value="Institution : "/>
                        <hr:institution value="#{staffLoanController.reportKeyWord.institution}"/>
                        <h:outputLabel value="Staff Category : "/>
                        <hr:completeStaffCategory value="#{staffLoanController.reportKeyWord.staffCategory}"/>
                        <h:outputLabel value="Designation : "/>
                        <hr:completeDesignation value="#{staffLoanController.reportKeyWord.designation}"/>
                        <h:outputLabel value="Roster : "/>
                        <hr:completeRoster value="#{staffLoanController.reportKeyWord.roster}"/>                

                    </h:panelGrid>

                    <h:panelGrid columns="2">
<!--                        <h:outputLabel value="With Account No"/>
                        <p:selectBooleanCheckbox value="#{staffLoanController.showAccountNo}" />-->
                        <p:commandButton ajax="false" value="Fill" action="#{staffLoanController.createLones()}" />
                        <p:commandButton ajax="false" value="Fill Deleted" action="#{staffLoanController.createLonesDeleted()}" />
                        <p:commandButton ajax="false" value="Fill For Paid" action="#{staffLoanController.createsheduleForPaidLones()}" />
                        <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" onclick="onSubmitButton();" >
                            <pe:exporter type="xlsx" target="tb5" fileName="hr_staff_loan_installment"  />
                        </p:commandButton>
                        <p:commandButton value="Print" ajax="false" action="#" >
                            <p:printer target="loaninstall" ></p:printer>
                        </p:commandButton>
                    </h:panelGrid>

                    <p:panel id="loaninstall" styleClass="noBorder summeryBorder" >
                        <f:facet name="header">
                            <h:outputLabel value="Loan And Advances" styleClass="noPrintButton"/>
                            <!--<p:commandButton ajax="false" value="Save Selected" action="#{staffLoanController.saveSelected}" style="float: right;" onclick="onSubmitButton();" styleClass="noPrintButton"/>-->
                        </f:facet>
                        <p:dataTable value="#{staffLoanController.paysheetComponents}" id="tb5"
                                     var="i" scrollHeight="200"
                                     rowKey="#{i.id}" rowIndexVar="a"
                                     selection="#{staffLoanController.selectedList}" >
                            <f:facet name="header">
                                <h:outputLabel value="#{staffLoanController.paysheetComponent.name}"/>
                            </f:facet>
                            <p:column  selectionMode="multiple" styleClass="noPrintButton" >                            
                            </p:column>
                            <p:column headerText="No">
                                <f:facet name="header">
                                    <h:outputLabel value="No"/>
                                </f:facet>
                                <h:outputLabel value="#{a+1}" >
                                </h:outputLabel>
                            </p:column>

                            <p:column headerText="Institution" sortBy="#{i.staff.workingDepartment.institution.name}"  >
                                <f:facet name="header" >
                                    <h:outputLabel value="Institution"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.workingDepartment.institution.name}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Department" sortBy="#{i.staff.workingDepartment.name}" >
                                <f:facet name="header" >
                                    <h:outputLabel value="Department"  />
                                </f:facet>

                                <h:outputLabel value="#{i.staff.workingDepartment.name}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Roster"  >
                                <f:facet name="header">
                                    <h:outputLabel value="Roster"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.roster.name}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="EMP Code" sortBy="#{i.staff.codeInterger}" >
                                <f:facet name="header">
                                    <h:outputLabel value="EMP Code"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.code}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Bank" sortBy="#{i.staff.bankBranch.institution.name}"  >
                                <f:facet name="header">
                                    <h:outputLabel value="Bank"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.bankBranch.institution.name}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Acc. No" sortBy="#{i.staff.accountNo}"  >
                                <f:facet name="header">
                                    <h:outputLabel value="Acc. No"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.accountNo}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="componentType" rendered="false">
                                <f:facet name="header">
                                    <h:outputLabel value="componentType"  />
                                </f:facet>
                                <h:outputLabel value="#{i.paysheetComponent.componentType}"/>
                            </p:column>
                            <p:column headerText="Roster">
                                <h:outputLabel value="#{i.staff.roster.name}"/>
                            </p:column>
                            <p:column headerText="Starting Balance">
                                <h:outputLabel value="#{i.startingBalance}"/>
                            </p:column>

                            <p:column headerText="From"  >
                                <f:facet name="header">
                                    <h:outputLabel value="From"  />
                                </f:facet>
                                <p:cellEditor>  
                                    <f:facet name="output">
                                        <h:outputLabel value="#{i.fromDate}">
                                            <f:convertDateTime pattern="dd MMMM yyyy"/>
                                        </h:outputLabel>
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:calendar value="#{i.fromDate}" pattern="dd MM yyyy" navigator="true"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="To" >
                                <f:facet name="header">
                                    <h:outputLabel value="To"  />
                                </f:facet>
                                <p:cellEditor>  
                                    <f:facet name="output">
                                        <h:outputLabel value="#{i.toDate}">
                                            <f:convertDateTime pattern="dd MMMM yyyy"/>
                                        </h:outputLabel>
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:calendar value="#{i.toDate}" pattern="dd MM yyyy" navigator="true"/>
                                    </f:facet>
                                </p:cellEditor>

                            </p:column>

                            <p:column headerText="Grade" >
                                <f:facet name="header">
                                    <h:outputLabel value="Grade"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.grade.name}"/>                           
                            </p:column>

                            <p:column headerText="Category" >
                                <f:facet name="header">
                                    <h:outputLabel value="Category"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.staffCategory.name}"/>
                            </p:column>

                            <p:column headerText="Designtion" >
                                <f:facet name="header">
                                    <h:outputLabel value="Designtion"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.designation.name}"/>
                            </p:column>
                            <p:column headerText="Resign Date" >
                                <f:facet name="header">
                                    <h:outputLabel value="Resign Date"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.dateLeft}">
                                    <f:convertDateTime pattern="dd MMMM yyyy"/>
                                </h:outputLabel>
                            </p:column>
                            <p:column headerText="Staff" >
                                <f:facet name="header">
                                    <h:outputLabel value="Staff"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staff.person.nameWithTitle}"/>
                            </p:column>                   
                            <p:column headerText="Loan Name" >
                                <f:facet name="header">
                                    <h:outputLabel value="Loan Name"  />
                                </f:facet>
                                <h:outputLabel value="#{i.paysheetComponent.name}"/>
                            </p:column>
                            <p:column headerText="Bank" >
                                <f:facet name="header">
                                    <h:outputLabel value="Bank"  />
                                </f:facet>
                                <h:outputLabel value="#{i.bankBranch.institution.name} - #{i.bankBranch.name}"/>
                            </p:column>
                            <p:column headerText="Loan No" >
                                <f:facet name="header">
                                    <h:outputLabel value="Loan No"  />
                                </f:facet>
                                <h:outputLabel value="#{i.loanNo}"/>
                            </p:column>

                            <p:column headerText="Account No" >
                                <f:facet name="header">
                                    <h:outputLabel value="Account No"  />
                                </f:facet>
                                <h:outputLabel value="#{i.accountNo}"/>
                            </p:column>

                            <p:column headerText="Loan Full Amount" >
                                <f:facet name="header">
                                    <h:outputLabel value="Loan Full Amount"  />
                                </f:facet>
                                <h:outputLabel value="#{i.loanFullAmount}"/>
                            </p:column>    
                            <p:column headerText="Monthly Installment" >
                                <f:facet name="header">
                                    <h:outputLabel value="Monthly Installment"  />
                                </f:facet>
                                <h:outputLabel value="#{i.staffPaySheetComponentValue}"/>
                            </p:column>
                            <p:column headerText="Cheque Number" rendered="#{staffLoanController.chequeDetails}">
                                <p:inputText autocomplete="off"  value="#{i.chequeNumber}"/>
                            </p:column>    
                            <p:column headerText="Cheque Date" rendered="#{staffLoanController.chequeDetails}">
                                <p:calendar navigator="true" value="#{i.chequeDate}" pattern="dd MM yyyy" />  
                            </p:column>

                            <p:column headerText="Compleated At" >
                                <f:facet name="header">
                                    <h:outputLabel value="Compleated At"/>
                                </f:facet>
                                <p:outputLabel value="#{i.completedAt}" >
                                    <f:convertDateTime pattern="dd MM yyyy" />
                                </p:outputLabel>
                                <!--<p:calendar value="#{i.completedAt}" pattern="dd MM yyyy" />-->
                            </p:column>

                            <p:column styleClass="noPrintButton">
                                <p:commandButton value="Edit" ajax="false">
                                    <f:setPropertyActionListener target="#{staffLoanController.current}"  value="#{i}" />
                                </p:commandButton>
                            </p:column>

                        </p:dataTable>
                    </p:panel>
                </p:panel>

            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
